package com.ywl.study.sharding.common.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class PreciseModuloShardingDatabaseAlgorithm implements PreciseShardingAlgorithm<Integer> {
    @Override
    public String doSharding(Collection<String> databases, PreciseShardingValue<Integer> preciseValue) {
        for (String database : databases) {
            if(database.endsWith(String.valueOf(preciseValue.getValue() % 2))){
                return database;
            }
        }
       throw new UnsupportedOperationException();
    }
}
